Skip to content
Advertisement

Tag: pandas

Momentum portfolio(trend following) quant simulation on pandas

I am trying to construct trend following momentum portfolio strategy based on S&P500 index (momthly data) I used Kaufmann’s fractal efficiency ratio to filter out whipsaw signal (http://etfhq.com/blog/2011/02/07/kaufmans-efficiency-ratio/) I succeeded in coding, but it’s very clumsy, so I need advice for better code. Strategy Get data of S&P 500 index from yahoo finance Calculate Kaufmann’s efficiency ratio on lookback period

pandas, apply with args which are dataframe row entries

I have a pandas dataframe ‘df’ with two columns ‘A’ and ‘B’, I have a function with two arguments and I would like to apply it row-by-row to df using the ‘apply’ function but I get the error whats happening here, it seems it takes df[‘A’] as the whole series! not just the row entry from that series as required.

covariance between two columns in pandas groupby pandas

I am trying to calculate the covariance between two columns by group. I am doing doing the following: Ideally, I would like to get the covariance between X and Y and not the whole variance-covariance matrix, since I only have two columns. Thank you, Answer You are almost there, only that you do not clear understand the groupby object, see

pandas – Merging on string columns not working (bug?)

I’m trying to do a simple merge between two dataframes. These come from two different SQL tables, where the joining keys are strings: I try to merge them using this: The result of the inner join is empty, which first prompted me that there might not be any entries in the intersection: But when I try to match a single

How can I manage units in pandas data?

I’m trying to figure out if there is a good way to manage units in my pandas data. For example, I have a DataFrame that looks like this: Currently, the measurement units are encoded in column names. Downsides include: column selection is awkward — df[‘width (m)’] vs. df[‘width’] things will likely break if the units of my source data change

Use None instead of np.nan for null values in pandas DataFrame

I have a pandas DataFrame with mixed data types. I would like to replace all null values with None (instead of default np.nan). For some reason, this appears to be nearly impossible. In reality my DataFrame is read in from a csv, but here is a simple DataFrame with mixed data types to illustrate my problem. I can’t do: nor:

Advertisement