Stack Exchange Network

Stack Exchange network consists of 175 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
3 views

Calculating QuantLib IborCoupon with / from given index fixing

How can I calc with QuantLib the coupon amount of a floating rate IborCoupon on the 3M Euribor Index with a given 3M Euribor Index Fixing? If I try the following Python code: ...
1
vote
1answer
69 views

Objective function: as close to equal weight as possible

I am having trouble coming up with a function to optimize the weights to be as equal as possible. It is a long-short portfolio with 6 positions weights is a cvx variable: [long, long, short, short, ...
2
votes
0answers
36 views

Constraints for a Long-Short Mean Variance Objective Function

Problem: I am trying to set up constraints for a long/short mean variance optimization problem. My constraints include: beta neutrality cash neutrality equality constraints on categories: <...
1
vote
1answer
73 views

python scipy optimize minimize arguments for Implied Volatility

I am having some trouble getting the 'correct' solution to a function where I am trying to utilize scipy.optimize.minimize. In the code below, I create a function <...
0
votes
0answers
43 views

Is it Possible to replicate SPAN?

I currently trade intraday Options on the nearest term expiry and futures. Both E-mini S&P. I am trying to replicate the SPAN margin calculation for the entire portfolio of options and futures. So ...
0
votes
0answers
40 views

John Ehlers - Forward Reverse EMA indicator calculation in pandas

I found a lot of translations of the John Ehlers - Forward Reverse EMA indicator in different specifics language (TRADESTATION, METASTOCK, ESIGNAL, WEALTH-LAB, AMIBROKER, NEUROSHELL TRADER, ...
-1
votes
0answers
22 views

Mean squared error calculation in portfolio optimization [duplicate]

Hi I'm having an explanation like below. I'm trying to find the minimum global portfolio and I found following explanation This explanation says the lambda can be identified via k-fold cross ...
1
vote
1answer
37 views

Stateful Technical Analysis Indicator Libray For Python

I an looking for a TA indicator library in python, that offers indicators you can update with ticks, in contrast to indicators that perform calculations on an entire data set. For example, an RSI ...
0
votes
1answer
63 views

Cross Validation for portfolio optimization

Hi I'm having an explanation like below. I'm trying to find the minimum global portfolio and I found following explanation I need to use validation methods to use the optimal parameters. Also i need ...
1
vote
2answers
211 views

Regularizers to compute Minimum Variance Portfolio weights

I need to compute the mimimum variance portfolio using different regularizers, to compare the results and use validation methods to find the optimal parameters. Currently my work has been performed ...
1
vote
1answer
72 views

Compare portfolio variance using different regularizers

I'm given a question like below. Using the 48_Industry_Portfolios_daily dataset: characterize/describe the dataset and focus on the global minimum variance portfolio. Compare the portfolio variance ...
4
votes
1answer
125 views

Optimal Portfolio from Efficient Frontier

I found this code on plotly site, using CVXOPT to find the efficient frontier, and then, the optimal Portfolio. The optimal function is ...
0
votes
0answers
28 views

QuantLib FuturesRateHelper how do I input Future type = 'ASX', the 'IMM' date check is causing Runtime Error

How do I input Future type = 'ASX', the 'IMM' date check is causing Runtime Error future_maturities 1 2019-06-14 2 2019-09-13 3 2019-12-13 4 2020-03-13 5 2020-06-12 6 2020-09-11 ...
2
votes
3answers
299 views

Efficient frontier doesn't look good

Hi I'm trying to draw an efficient frontier. Below is what I used. returns parameter consists of 9 column returns of portfolio. I selected 10,000 portfolios and this is how my efficient frontier ...
3
votes
1answer
61 views

forward + displacement

I I am trying to price a cap/floor using Quantlib in Python. the initial code from from this website: http://gouthamanbalaraman.com/blog/interest-rate-cap-floor-valuation-quantlib-python.html Here is ...
5
votes
2answers
156 views

Estimation of Risk-Neutral Densities Using Positive Convolution Approximation - Python

I'm trying to estimate the risk-neutral density through positive convolution approximation (introduced by Bondarenko 2002: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=375781). I'm currently ...
1
vote
1answer
72 views

How to take back-tested code and convert it to forward-testing code? (in Python)

How do you take back-tested code written using the zipline API and convert that into forward-testing code using the IB API (or better yet ib-insync API)? It seems like you would have to completely re-...
3
votes
1answer
68 views

Errors on Finite Differences + Implicit Scheme + Black & Scholes

I'm solving the classical Black & Scholes (BS) PDE for a European option using finite difference and the implicit scheme. In other words, I'm trying to solve $\displaystyle\frac{\partial V}{\...
1
vote
0answers
67 views

Derivative of the stock price and volume at time t

According to Forecasting of Jump Arrivals in Stock Prices: New Attention-based Network Architecture using Limit Order Book Data at page 9, I would be interested in deriving the the price (ask and bid ...
4
votes
0answers
62 views

Understanding and simulating the jumps in Merton's Jump-Diffusion SDE?

I found this great post deriving the solution to the Merton Jump-Diffusion SDE $$S_t = S_0\exp\left(\left(\mu - \frac{\sigma^2}{2}\right)t + \sigma W_t\right)\prod_{j=0}^{N_t}V_j$$ The first part of ...
2
votes
0answers
36 views

SquareRootProcess in QuantLib - Python

I would like to price an American put option using the SquareRootProcess class in QuantLib - Python but it seems that it does not exist. As the underlying follows the following model : $$\rm{d}S_t=...
1
vote
0answers
79 views

Holding Period Return abnormally high

I've been doing my Dissertation and I was told to create a value - weighted portfolio on the 1979's 200 largest cap corporations (based on Market Value). I was also told that the correct way to build ...
1
vote
0answers
45 views

Binomial Model Implementation Trouble - American and European options come out equal

I'm Trying to implement the binomial option price model in python and get reasonable performance by using memoization. I checked the output against a black and scholes model and for European options ...
0
votes
0answers
50 views

Rolling forecast using GARCH model

EDIT This is not a duplicate of my original question linked, since I have since overcome that problem and have posted an answer. Since solving the previous problem, I have run into the problem ...
1
vote
0answers
20 views

Drop NaN in a for loop for each column [closed]

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. ...
1
vote
0answers
55 views

Machine Learnign for Factor Model python [closed]

I have read several articles about Factor Model using Deep Learning or machine learning, but none of them post the code. Where can I find the python code for anything similar?
0
votes
0answers
37 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
1answer
85 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
vote
0answers
90 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
188 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
51 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
vote
1answer
147 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
87 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
242 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
105 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
84 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
397 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
671 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
251 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
490 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
43 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
149 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
60 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 ...
1
vote
1answer
106 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 ...
1
vote
0answers
22 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
204 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
230 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
90 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 ...
0
votes
1answer
154 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
625 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 ...