Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 239.027% Drawdown 1.100% Expectancy 0 Net Profit 1.687% Sharpe Ratio 4.159 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 62.235 Annual Standard Deviation 0.172 Annual Variance 0.03 Information Ratio 4.093 Tracking Error 0.172 Treynor Ratio 0.011 Total Fees $3.29 |
import numpy as np import pandas as pd class portfolioLogReturnsExample(QCAlgorithm): def Initialize(self): self.cash = 100000 self.SetStartDate(2013,10, 7) #Set Start Date self.SetEndDate(2013,10,11) #Set End Date self.SetCash(self.cash) #Set Strategy Cash self.symbol = "SPY" self.AddEquity(self.symbol, Resolution.Daily) # Create empty DataFrame to store portfolio value self.df = pd.DataFrame() def OnData(self, data): if not self.Portfolio.Invested: self.SetHoldings(self.symbol, 1) self.df = self.df.append({"PortfolioValue":self.cash},ignore_index=True) return # Append dictionary to DataFrame self.df = self.df.append({"PortfolioValue":self.Portfolio.TotalHoldingsValue},ignore_index=True) # Calculate log returns logPct = np.log(self.df["PortfolioValue"]).diff().dropna() # Print log returns self.Log(str(logPct))