Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
25 views

What volatility to use to estimate BDT?

I am attempting to estimate the value of a bond with prepayment option (callable bond). In order to do so, I am fitting a lattice to the Libor Swap curve using a BDT model. The measurement date is ...
1
vote
0answers
34 views

Is this the correct way to forecast stock price volatility using GARCH

I am attempting to make a forecast of a stock's volatility some time into the future (say 90 days). It seems that GARCH is a traditionally used model for this. I have implemented this below using ...
-1
votes
0answers
44 views

Euler scheme to simulate trajectories + Python Code

Question: Euler scheme to simulate trajectories of S + Python code to get independent trajectories of S? For solving a problem I have the following assumptions: stochastic basis (Ω,FT,(Ft)t≥0,P) ...
1
vote
0answers
50 views

Poor results forecasting stock price volatility using Python's GARCH model

As far as I understand, forecasting stock price volatility should be more achievable than forecasting absolute prices or returns. It seems as though GARCH models are the traditional and most widely ...
0
votes
2answers
88 views

Least-Squares-Monte-Carlo by Neural Network Estimator for pricing American Option Python

First I did the LSM (Longstaff-Schwartz) to understand how its work to price an American option. code for standard_normal ...
2
votes
0answers
30 views

QuantLib - Synthetic deposit/FRA rates in yield curve

In my flat forwards dollar curve implemented in QuantLib I would like to add the following instrument: Today is 12/28/2018 Pillar quote is 1% p.a. (ACT/360) Pillar start is 1/30/2019 (specific ...
-1
votes
0answers
22 views

Backing out market returns and Beta using multiple assets' excess returns and raw returns

I have a dataset where every asset's daily returns and excess returns throughout a number of years are available. Excess returns being: returns - beta * market returns, where beta is calculated using ...
1
vote
1answer
129 views

Crossing the spread as a ML signal

In the optic of high-frequency trading, most of the standard trading algorithms work on the principle of mid-price prediction or mid-price movement prediction. However a big drawback of this technique ...
1
vote
1answer
82 views

How to go about computing RSI?

I've written python code that I believe computes RSI. I wrote the code based on what I saw in stockcharts.com found here Here is the code: ...
3
votes
3answers
157 views

Compute tangency portfolio with asset allocation constraints

I am looking to compute the tangency portfolio of the efficient frontier, but taking into account min_allocations and ...
-2
votes
4answers
86 views

Sending order to Forex or Stocks from Python strategy

I have my own strategy developed in Python. But I couldn't find a reliable method to send, close, and modify orders using Python. Are there any tools that help order management using Python? I also ...
1
vote
0answers
72 views

Time series analysis for stock prices

I am using GARCH model to simulate price of an index for 7 years. For input I am using difference of Log of prices (log of return). GARCH(1,1) has the lowest AIC, and I found parameters for the ...
0
votes
1answer
169 views

Python package for option pricing models?

Is there a good python package for various option pricing models, e.g., Heston, SABR, etc? I found that it's even hard to find a good python implementation of Black-Scholes model (i.e., price + IV + ...
1
vote
2answers
428 views

Predicting stock returns with GARCH in Python

I have seen this post: Correctly applying GARCH in Python which shows how to correctly apply GARCH models in Python using the arch library. Now I am wondering how I ...
3
votes
1answer
151 views

Why my implementation of CRR model does not converge?

Recall that CRR (Cox-Ross-Rubinstein) model for option pricing is the usual binomial tree model with $u$ (up-factor) and $p$ (one of the risk-neutral probabilities) defined as follows: $$u = e^{\sigma\...
0
votes
2answers
222 views

How to calculate “portfolio cumulative return” from individual price data and weight of them?

I'm trying to run backtest in a vectorized way using Python Pandas and need to calculate a portfolio cumulative return from price data and weight of asset data. I ...
1
vote
0answers
39 views

Is my coding for my kalman filter off when testing this specific set of pairs?

My kalman filter seems to be off for this specific set of pairs I'm looking at. As you can see, in the kalman filtered linear regression, there seems to be an outlying blue line nowhere near the data ...
0
votes
1answer
114 views

Structured Payoff Scripting in QuantLib

I'm trying to price a snowball payoff in quantlib and would like to create a payoff like: $$Coupon = PreviousCoupon + FloorPayoff$$ Would the payoff class be able to reference the previous coupon? ...
0
votes
1answer
44 views

how to change the value set by the addFixing method in QuantLib

Suppose we have had constructed an index for forecasting future interests of a floating bond, and as suggested by the official document, I used addFixing method to set a past fixing for the current ...
0
votes
1answer
79 views

Swing option pricing in QuantLib-Python

Is it possible to use the QuantLib python wrapper to price swing options? I've seen the QuantLib Github repository contains a C++ implementation, swingoption.cpp, but have found no reference to swing ...
0
votes
0answers
20 views

Simulating Taxed Equity Return Series (U.S.)

I'm looking to learn how to correctly simulate taxes on dividends and capital gains on simulated return series for U.S. Equities with dividend reinvestment. I understand I will have to keep track of ...
3
votes
1answer
164 views

Option Strategy: Python Implementation Advice

I've been tasked to create and backtest an option strategy. The strategy, in vague terms, is to essentially write call options on securities in a universe, i.e., selling insurance. I have an idea of ...
2
votes
1answer
209 views

Limit and Market Order for training a ML model

Goal : Using deep learning to build a ML model which would predict the right places where a stock price will increase, decrease or stay stable. For the current question, assume the labels are well ...
-2
votes
1answer
81 views

Separate market and limit orders from market depth/tick data

From the website https://www.algoseek.com/equities/, we can get a sample of the full depth market/tick data. From the paper https://arxiv.org/pdf/1710.03870.pdf page 8, I would like to extract the ...
-1
votes
1answer
134 views

How to simulate this Gamma expansion in a Python way

Here is the simulation that I want to do: For each of the 10 million simulation paths, I have n = 100 lambda values in sequence (the lambda vector is the same for all paths), Using each of the lambda ...
-1
votes
1answer
610 views

Choosing programming language for the next generation of a pricing library [closed]

If I were to start development of a pricing library, which programming language would be most suitable to satisfy the following needs: Implement highly parallelizable pricing models using GPU or any ...
0
votes
0answers
138 views

Calculate tenor wise DV01 of a Swap in Quantlib Python, i.e. Key-rate Duration

Is there a way I can get DV01 breakup of a Swap across different tenors of the deal in Quantlib-Python. The question asked here, follows the basic method of re-valuing the swap by shifting the curve ...
1
vote
0answers
77 views

Binary Options: convert from “Cash or Nothing” to “Asset or Nothing”

I have a formula that uses Black-Scholes to compute the implied pricing of a "Cash or Nothing" binary option on the price of a currency. The option is priced/traded in the same currency as S, K and ...
3
votes
1answer
172 views

Quantlib derivative valuation from zero curve

I have newly started with Quantlib-Python for valuing derivatives. In all the examples stated in this bolg or in other places, market quote is inserted and bootstrapping is done via individual rate ...
3
votes
1answer
118 views

QuantLib in Python : Execution time with OISRateHelper compared to Swap/Deposit RateHelper

I have been working on valuation of interest rate swaps using dual curve bootstrapping. And for this I use OISRateHelper to create a discount term structure using OIS rates. The entire code below : <...
1
vote
1answer
222 views

Black-Scholes for Binary Option

Something is wrong with this python code designed to apply Black Scholes to the price of a binary option (all or nothing, 0 or 100 payout). The results I get here is 0.4512780109614. Which I know ...
2
votes
4answers
250 views

Backtesting Fundamental Equity Strategies in Python

I am trying to run a local backtest using Python and Zipline seems to be the most popular package out there. Does any one have isnight on ingesting fundamental data for the backtest? The documentation ...
0
votes
0answers
156 views

Quantlib Python: Issue withg Heston MC Paths generation

I am trying to price a corridor Variance Swap with Heston. I am generating paths with the following code, however I get weird results of the MC simulation. Any idea why ? ...
0
votes
1answer
306 views

Why are my eigenvalues coming out negative for my positive definite covariance matrix?

I have a 51 x 51 covariance matrix that is derived from historic forward rates that is positive definite. I know it is because in Python np.cholesky returns a correct cholesky decomposition. However, ...
0
votes
1answer
300 views

Automatically get iShares ETF holdings

I heard that ETF's must publicly report their holdings all the time. I have seen that for example on the iShares website I can download the list of holdings as a csv file: https://www.ishares.com/us/...
1
vote
0answers
93 views

Chat bot for traders [closed]

In the framework of my internship at a bank, I want to write a chat bot program in Python that allows our bond traders via their Bloomberg terminal chat box application to type in structured command ...
2
votes
1answer
126 views

How to interpret and define statistics of GBM output

I am trying to model the future prices of a number of commodities. For this, I am applying geometric Brownian motion, writing a Monte Carlo code in Python. Given that I want to estimate tommorows ...
1
vote
2answers
111 views

How to change the YieldTermStructureHandle's referenceDate in QuantLib

Suppose we have already known the dates and rates of a spot rate curve, and I passed the data to the ZeroCurve class to construct a discount curve for bond pricing. What I wanna find is how to change ...
1
vote
1answer
194 views

Implementing the Sharpe's return-based style analysis on Python

I am trying to implement the Sharpe's return-based style analysis on Python. The problem is formulated as follows: ...
1
vote
2answers
150 views

Working with time series with different resolutions

I’m looking at making predictions of close prices (stocks/commodities), and have access to various data sources to help predict. However, most of these sources are in a different time frame, ...
1
vote
1answer
90 views

Pricing an option with sparse data, high underlying volatility and returns

I'm currently pricing American and European options on an underlying with sparse data (interpolated), high annual volatility and returns over the last year around 300%. The product isn't similar to ...
2
votes
2answers
254 views

QuantLib-Python: How to set fixed reference dates when bootstrapping the term structure?

I am borrowing from an example in the "Quantlib Python Cookbook" section 7, to ask my question. To make the point as clear as possible I simplify the code a bit. The aim is to strip the EONIA curve ...
1
vote
1answer
95 views

Using DayCounter ActualActual.ISMA in QuantLib

Suppose we have a semiannual coupon bond. The calculation date is 5/8 2017. The ex-coupon date is 4/20 2017 and next coupon date is 10/20 2017. ...
1
vote
1answer
112 views

QuantLib-Python: What is “index = Euribor1Y(term_structure)” doing?

I am currently reading thorugh the QuantLib-Python cookbook to learn about this nice pice of software. On page 141 I encountered a block of code that made me wonder what it is exactly doing. The code ...
2
votes
1answer
88 views

Quantlib - model changes in option value on day of expiry

I'm trying to model option value changes during the progression of the last trading day before expiry. All option pricing Quantlib examples that I've seen work with day-level granularity. I'm ...
1
vote
1answer
276 views

Pricing fixed coupon bond with ytm in QuantLib python

I'm new to QuantLib and I'm confused about ZeroCurve in YieldTermStructureHandle The start date is Oct 20, 2001. Assuming the ...
1
vote
2answers
477 views

Efficient algorithm for calculating Beta coefficient

I'm using Python/Pandas. Using naive nested for-loops to do Beta calculation for all ~5k stocks by ~5k days (moving window ~250 days) is unbearably slow. Is there any fast and elegant way to ...
2
votes
1answer
874 views

How to calculate Sharpe Ratio from $ returns?

I have a pairs strategy that I am trying to calculate the sharpe ratio for. Currently I am using python for my analysis and calculation. I have a dataframe that contains the cumulative returns in $'s ...
2
votes
1answer
97 views

QuantLib-Python: Splitting the NPV of an option into intrinsic & time

I am right now working throught the "cookbook" of Goutham Balaraman & Luigi Ballabio. By the way a very nice introduction into QuantLib-Python and a good starting point :-) In section four there ...
1
vote
0answers
113 views

Mean Variance Optimization of 2000 pairs of securities (Python)

I would like to take the opportunity to ask for your help on an assignment I'm trying to complete. For this 'Modern Robo Advisory' course we are asked to solve a (target) goal-based investment ...