Overall Statistics
Total Orders
360
Average Win
3.65%
Average Loss
-3.78%
Compounding Annual Return
2.274%
Drawdown
61.000%
Expectancy
0.052
Start Equity
100000
End Equity
138832.61
Net Profit
38.833%
Sharpe Ratio
0.103
Sortino Ratio
0.117
Probabilistic Sharpe Ratio
0.009%
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
0.97
Alpha
0.025
Beta
0.001
Annual Standard Deviation
0.239
Annual Variance
0.057
Information Ratio
-0.128
Tracking Error
0.346
Treynor Ratio
18.474
Total Fees
$15375.75
Estimated Strategy Capacity
$100000000.00
Lowest Capacity Asset
EEM SNQLASP67O85
Portfolio Turnover
13.50%
#region imports
from AlgorithmImports import *
#endregion
# https://quantpedia.com/Screener/Details/61


class LunarCycleAlgorithm(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2004, 1, 1)
        self.set_end_date(2018, 8, 1)
        self.set_cash(100000)
        # import the custom data 
        self.add_data(MoonPhase, "phase", Resolution.DAILY)
        self.add_equity("EEM", Resolution.DAILY)
        self.set_benchmark("EEM")
    
    def on_data(self, data):
        # long in emerging market index ETF 7 days before the new moon (It's the Last Quarter)
        if self.securities["phase"].price == 3 and not self.portfolio["EEM"].is_long:
            self.set_holdings("EEM", 1)
        # short on emerging market index ETF 7 days before the full moon (It's the First Quarter)
        elif self.securities["phase"].price == 1 and not self.portfolio["EEM"].is_short:
            self.set_holdings("EEM", -1)
        

class MoonPhase(PythonData):
    "Class to import Phases of the Moon data from Dropbox"
        
    def get_source(self, config, date, is_live_mode):
        return SubscriptionDataSource(
            "https://www.dropbox.com/s/q9rt06tpfjlvymt/MoonPhase.csv?dl=1", 
            SubscriptionTransportMedium.REMOTE_FILE)

    def reader(self, config, line, date, is_live_mode):
        index = MoonPhase()
        index.symbol = config.symbol
        try:
            # Example File Format: (Data starts from 01/07/2004)
            # date                 phase
            # 2004 Jan 07 15:40    Full Moon
            data = line.split(',')
            if data[0] == "date": return None
            index.time = datetime.strptime(data[0], "%Y %b %d %H:%M").replace(hour=0, minute=0)
            if data[1] == "New Moon":
                index.value = 0
            elif data[1] == "First Quarter":
                index.value = 1
            elif data[1] == "Full Moon":
                index.value = 2
            elif data[1] == "Last Quarter":
                index.value = 3
        except:
            return None
            
        return index