首页 > 解决方案 > Cython syntax for dataframe of dates and dictionaries as inputs to the function

问题描述

I am a python user with moderate experience in writing codes and recently I noticed that I can use cython for sequential models like backtesting codes to make it faster. The problem is that imagine I have a function called backtesting with arguments given below:

def backtest(daterange,price_dict,tickers_dict,):
return result

where daterange is a dataframe of dates.

price_dict is a dictionary of daily prices based on company ticker and date given (so it is a dictionary with 2 levels of keys --> price_dict[ticker][date] -> price

tickers_dict is a dictionary of picked tickers based on dates so it is like tickers_dict[date] --> gives a list of tickers

result is a dataframe with daily equity values of the portfolio calculated inside the function.

How can I define all of these in cython using cdef or cpdef? what is the syntax for it? It has driven me crazy t o find the right syntax! thanks

标签: pythonpandascython

解决方案


推荐阅读