import sys import numpy as np import pandas as pd from myOptimAction import myOptimAction from profitEstimateOpen import profitEstimateOpen df = pd.read_csv(sys.argv[1]) transFeeRate= float(sys.argv[2]) priceVec = df["Adj Close"].values actionVec = myOptimAction(priceVec, transFeeRate) returnRate = profitEstimateOpen(priceVec, transFeeRate, actionVec)
stockHolding[i][a] -= sellStock # Stocking holding stockHolding[i][b] += getCash * ( 1 - transFeeRate) / currentPriceBuy # Buy stock using cash realAction[i] = 2 else: assert False else: assert False # calculate total cash you get at last day total = capital for stock in range(stockCount): currentPriceVec = priceMat[actionMat[-1][0]] total += stockHolding[-1][stock] * currentPriceVec[stock] * ( 1 - transFeeRate) # Total asset, including stock holding and cash returnRate = (total - capitalOrig) / capitalOrig # Return rate of this run return returnRate if __name__ == "__main__": print("Reading %s..." % (sys.argv[1])) file = sys.argv[1] # input file df = pd.read_csv(file, delimiter=' ') transFeeRate = float(sys.argv[2]) # Rate for transaction fee priceMat = df.values # Get price as the m×n matrix which holds n stocks' price over m days actionMat = myOptimAction(priceMat, transFeeRate) # Obtain the suggested action rr = computeReturnRate(priceMat, transFeeRate, actionMat) # Compute return rate print("rr=%f%%" % (rr * 100))
#import sys #import numpy as np import pandas as pd from myOptimAction import myOptimAction from profitEstimateOpen import profitEstimateOpen #df = pd.read_csv(sys.argv[1]) #transFeeRate= float(sys.argv[2]) df = pd.read_csv("SPY.csv") transFeeRate= float(0.01) priceVec = df["Adj Close"].values actionVec = myOptimAction(priceVec, transFeeRate) returnRate = profitEstimateOpen(priceVec, transFeeRate, actionVec) print(returnRate[0])