/** Script to execute calculation DolphinDB Inc. DolphinDB server version: 2.00.8 JIT Storage engine: OLAP Last modification time: 2023.02.09 */ /* * Read data */ data = select * from loadTable("dfs://optionPrice", "optionPrice") where sym =`510050 // Read option prices closPriceWideMatrix = panel(data.codes, data.tradeDate, data.closePrice) // Read ETF prices etfPriceWideMatrix = panel(data.codes, data.tradeDate, data.etfprice) // Read reference data contractInfo = select * from loadTable("dfs://optionInfo", "optionInfo") where sym =`510050 // Read trading calendars tradingDatesAbsoluteFilename = "/hdd/hdd9/tutorials/jitAccelerated/tradedate.csv" startDate = 2015.02.01 endDate = 2022.03.01 allTradingDates = loadText(tradingDatesAbsoluteFilename) tradingDates = exec tradedate from allTradingDates where tradedatestartDate /* * Single day calculation performance test */ // Define single day performance test function def testOneDayPerformance(closPriceWideMatrix, etfPriceWideMatrix, contractInfo, targetDate){ targetDate_vec = [targetDate] r = 0 optionTodayClose = getTargetDayOptionClose(closPriceWideMatrix, targetDate_vec) validContractsToday = optionTodayClose.columnNames() etfTodayPrice = getTargetDayEtfPrice(etfPriceWideMatrix, targetDate_vec) KPrice, dayRatio, CPMode = getTargetDayContractInfo(contractInfo, validContractsToday, targetDate_vec) timer{ impvMatrix = calculateImpv(optionTodayClose, etfTodayPrice, KPrice, r, dayRatio, CPMode) deltaMatrix = calculateDelta(etfTodayPrice, KPrice, r, dayRatio, impvMatrix, CPMode)\(etfTodayPrice*0.01) gammaMatrix = calculateGamma(etfTodayPrice, KPrice, r, dayRatio, impvMatrix)\(pow(etfTodayPrice, 2) * 0.0001) vegaMatrix = calculateVega(etfTodayPrice, KPrice, r, dayRatio, impvMatrix) thetaMatrix = calculateTheta(etfTodayPrice, KPrice, r, dayRatio, impvMatrix, CPMode) } todayTable = table(validContractsToday as optionID, impvMatrix.reshape() as impv, deltaMatrix.reshape() as delta, gammaMatrix.reshape() as gamma, vegaMatrix.reshape() as vega, thetaMatrix.reshape() as theta) todayTable["tradingDate"] = targetDate todayTable.reorderColumns!(["optionID", "tradingDate"]) return todayTable } // Execute single day performance test function oneDay = testOneDayPerformance(closPriceWideMatrix, etfPriceWideMatrix, contractInfo, 2022.02.28) /* * Multi-day parallel calculation performance test */ // Create a table variable to store the calculation results result = table( array(SYMBOL, 0) as optionID, array(DATE, 0) as tradingDate, array(DOUBLE, 0) as impv, array(DOUBLE, 0) as delta, array(DOUBLE, 0) as gamma, array(DOUBLE, 0) as vega, array(DOUBLE, 0) as theta ) // Execute multi-day parallel calculation function calculateAll(closPriceWideMatrix, etfPriceWideMatrix, contractInfo, tradingDates, result)