Package: rofa
IntroductionInterests inQuant investing(or trading) are growing fast every day. Many people try to create profitable strategies and test it using past data (It is called ‘backetest’ by quants). It is good phenomenon in that it can prevent people from wasting their money with unverified strategies, or just news) and enables investing with more statistical approaches. However, some people started to cling to just higher CAGR (compound annual growth rate) and total returns and ignore other statistical performance to ensure robustness of strategy. CAGR is just one factor to evaluate strategy, and if you don’t care other evaluations, your investing can be in danger in the future. See below pictures.‘Strategy B’ has underperformed ‘Strategy A’ before 2014, but it outperformed ‘Strategy A’ at the end in the perspective of total returns and CAGR. But as you know, we cannot say ‘Strategy B’ is more robust than ‘Strategy A’Rofais abbreviation for ‘Robust Factor’. This module helps you to check factor’s robustness. All you do is just prepare data with certain formats, and ask rofa to simulate, and evaluate, and make summarized graph of it. Now you had powerful quant tool‘Rofa’.Installationpip install rofaNoteYou can use any editor to use python, but I recommend using jupyter notebook to start. jupyter notebook allows you to interactively run python code block by block. You can install jupyter notebook as follows.pip install jupyterTo start itjupyter notebookGetting startedImport RofaFirst of all, importrofaandQuantileSimulatorfrom rofaimportrofafromrofaimportQuantileSimulatorRegistering daily returns dataUnfortunately, rofa does not have any data with it. So, in order to run simulation, you need to**register daily returns data(pandas DataFrame). If you register returns data once, rofa will find returns data later without re-registering (You can change this option usingsave=False).importpandasaspd# Read Close Datareturns=pd.read_pickle('../data/returns.pkl')# Your returns datarofa.register_returns(returns)Notereturns dataframe data must have following format, where columns are asset symbols and index is date.Prepare dataData (pandas Dataframe) must have formats where columns are asset symbols (or code) and index is date such as returns. You can download data used in this example inhere.# Read Close Dataclose=pd.read_pickle('../data/close.pkl')# Your dataQuantileSimulatorquan_sim=QuantileSimulator(close,rebalance_freq=10,bins=5)In QuantileSimulator, first argument accepts factor data (close here). Additionaly, you can setrebalance_freq,bins,tax_rate,weight_modeland etc.Run simulationJust run the simulation. Simulation logics are all done byrofaquan_sim.run()Plot portfolio returnsSimulation classes has plotter plugin inside it, which makes it possible to visuallize the simulation result.quan_sim.plotter.plot_portfolio_returns()From portfolio returns graph, we can compare overall performances and drawdowns of each portfolio.Plot performance metrics (CAGR, MDD, Sharpe, Calmar)From this graph, we can check performance metrics and check if there is strong relationship between factor and performance.Plot rolling performance.Wait, we can plot all at onceYou might have though about how come I can memorize all plot methods. Here’s a method for you.plot_allplots all above. Super simple!quan_sim.plotter.plot_all()TODOAdd more performance indicatorsOptimize code for efficiency. There are some points to make code inefficientCreateLongShortPlotterand make all methods used inQuantilePlotterAdd statistical analysis plugin such asLinear Regression,t-test, andANOVACreateNakedSimulatorand add plotter pluginsCreateEvaluator PluginLaterUsenumbaorcythonto improve performanceBetter documentation!