Monte Carlo¶
The Monte Carlo method is implemented in finquant.monte_carlo
.
The module provides a class MonteCarlo
which is an implementation of the
Monte Carlo method and a class MonteCarloOpt
which allows the user to perform a
Monte Carlo run to find optimised financial portfolios, given an intial portfolio.

class
finquant.monte_carlo.
MonteCarlo
(num_trials=1000)¶ An object to perform a Monte Carlo run/simulation.

__init__
(num_trials=1000)¶ Input: num_trials: int
(default:1000
), number of iterations of the Monte Carlo run/simulation.

run
(fun, **kwargs)¶ Input: fun: Function to call at each iteration of the Monte Carlo run. kwargs: (optional) Additional arguments that are passed to fun. Output: result: List of quantities returned from fun at each iteration.


class
finquant.monte_carlo.
MonteCarloOpt
(returns, num_trials=1000, risk_free_rate=0.005, freq=252, initial_weights=None)¶ An object to perform a Monte Carlo run/simulation for finding optimised financial portfolios.
Inherits from MonteCarlo.

__init__
(returns, num_trials=1000, risk_free_rate=0.005, freq=252, initial_weights=None)¶ Input: returns: A pandas.DataFrame
which contains the returns of stocks. Note: If applicable, the given returns should be computed with the same risk free rate and time window/frequency (argumentsrisk_free_rate
andfreq
as passed down here.num_trials: int
(default:1000
), number of portfolios to be computed, each with a random distribution of weights/allocation in each stockrisk_free_rate: float
(default:0.005
), the risk free rate as required for the Sharpe Ratiofreq: int
(default:252
), number of trading days, default value corresponds to trading days in a yearinitial_weights: list
/numpy.ndarray
(default:None
), weights of initial/given portfolio, only used to plot a marker for the initial portfolio in the optimisation plot.Output: opt: pandas.DataFrame
with optimised investment strategies for maximum Sharpe Ratio and minimum volatility.

optimisation
()¶ Optimisation of the portfolio by performing a Monte Carlo simulation.
Output: opt_w: pandas.DataFrame
with optimised investment strategies for maximum Sharpe Ratio and minimum volatility.opt_res: pandas.DataFrame
with Expected Return, Volatility and Sharpe Ratio for portfolios with minimum Volatility and maximum Sharpe Ratio.

plot_results
()¶ Plots the results of the Monte Carlo run, with all of the randomly generated weights/portfolios, as well as markers for the portfolios with the minimum Volatility and maximum Sharpe Ratio.

properties
()¶ Prints out the properties of the Monte Carlo optimisation.
