Questions tagged [python]

Python is a dynamically and strongly typed programming language whose design philosophy emphasizes code readability. Two significantly different versions of Python (2 and 3) are in use. Please mention the version that you are using when asking a question about Python.

275 questions
10
votes
5 answers

How can I calculate the Maximum Drawdown MDD in python

I need to calculate the a time dynamic Maximum Drawdown in Python. The problem is that e.g.: ( df.CLOSE_SPX.max() - df.CLOSE_SPX.min() ) / df.CLOSE_SPX.max() can't work since these functions use all data and not e.g. considering the minimum only…
hb.klein
  • 165
  • 1
  • 2
  • 7
5
votes
3 answers

calculate YTD return / find first available datapoint of a year in python

I need to calculate the year-to-date relative return of a given dataset. I usually caculate the cumulative relative return with this simple function: def RelPerf(price): RelPerf = (price/price[0]) return RelPerf The problem ist that I…
hb.klein
  • 165
  • 1
  • 2
  • 7
2
votes
2 answers

Is there a python package/function that returns the trading time between two timestamps?

I have two timestamps, e.g. 2017-04-11 and 2017-07-08, or 2017-04-11 21:00:57 and 2017-07-08 12:41:54 and I am looking for a Python package/function that returns the total trading time between these two timestamps (i.e. excluding the time during…
Franck Dernoncourt
  • 507
  • 1
  • 7
  • 19
1
vote
0 answers

How does the mean interest rate of a loan shift over time?

I have a loan dataset (300MB) that comes from the Lending Club and I would like to know how has the average interest rate of a loan varied over time. I have the int_rate column but I'm not familiar enough with the names to know how much a debt…
1
vote
0 answers

TWS API Python_Remaining Positions

I am trying to get the number of filled/remaining positions using the function orderStatus() under EWrapper class. I tried something like, print(p.orderStatus(orderId=6, filled)), which didn't work. Please help. Thanks,
1
vote
1 answer

Can someone confirm if I am correct about these numbers on companies' financial documents?

I am looking to implement Piotroski's F-score Value strategy discussed in the paper "Piotroski, J. D. (2000). Value investing: The use of historical financial statement information to separate winners from losers. Journal of Accounting Research, 38,…
David Frick
  • 111
  • 3
1
vote
0 answers

Drop NaN in a for loop for each column

I will try to explain my problem. So I have two DataFrames , Df1 and Df2. Each of them has 3 columns and 4 rows. I will solve a quadratic functions with np.polyfit. M=3 for t in range(M-1,0,-1): regs = np.polyfit(Df1[:,t],Df2[:,t+1],2) C =…
joey
  • 7
  • 3
1
vote
1 answer

Hourly historical data for US stocks: how to download for free in Python

I have to download last 10 year price data at hourly intervals. I tried trying the link below with i= 2600 (2600 seconds or 1 hour) p=10Y or 2500d https://finance.google.com/finance/getprices?q=LHA&p=10Y&i=3600&f=d,c,h,l,o,v please can you help me…
Bill C
  • 11
  • 2
0
votes
1 answer

need help with Donchian-channels function!

I want to be able to plot Donchian-channels. It's probably easier to use numpy but, am not that fluent with numpy yet so i thought i could make a function that takes two arrays as input(Highs and lows), make a little size-limited-dynamical-array…
0
votes
1 answer

KeyError in Python code used to determine a trade signal for Pair Trading

I'm basically running some code as follows. Basically I'm just retrieving pairs of stocks (laid out as Row 1-Stock 1,2, Row 2-Stock 1,2 and so on, where Stock 1 and 2 are different in each row) from a CSV File. I then take in data from Yahoo…
Jojo
  • 895
  • 8
  • 20
-1
votes
1 answer

Removing NaN Values in Python Quantopian

I am trying to make a histogram in numpy but numpy.histogram seems to really hate NaN values. I have tried removing NaN values from a list called data in three different ways and Quantopian doesn't let me use any of those three ways: 1.) TypeError:…
old-profile
  • 101
  • 1
  • 4
-1
votes
1 answer

Yahoo finance CSV Thursday only data

Using python 3.5 In yahoo finance I downloaded banknifty .csv the sheet needs to depict three coin toss per day. At random time . However i couldnt automate the date to repeat three times before next date kicks in.help please
sujith
  • 1
  • 2