-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the misc wiki!
This repository contains some ad hoc scripts written on an as-you-go basis.
The scripts "prime_n.py", "prime_n.R", and "prime_n.m" identify and print the first n prime numbers. These scripts are optimised to reduce the number of trials. The running time is printed to compare the execution of similar scripts in Python vs R vs MATLAB. Execution times are:
- 0.001 sec for Python
- 0.018 sec for Matlab
- 0.029 sec for R
The script "term_optimise.R" aims to track and replicate a target series defined in the last column of "term_quotes.csv". The csv file contains six columns:
- "date_missing" the monthly time series accompanying the missing values to be constructed (second column);
- "price_build": the price series to be completed with the first two observations provided matching the dates in the first column;
- "quarter block" quarterly time series for which market prices are already observed (fourth column);
- "mean_Q" quarterly averages for observed values;
- "date_base": the monthly time series accompanying the target series (sixth column);
- "Reference curve": the target price series provided as actual forward agreements.
The goal is to track the target series (green line in the figure below) from the starting points provided in the csv file. This tracking must satisfy the market conditions (i.e. match the quarterly averages as close as possible) and have maximum correlation relative to the target series. The latter configuration is formulated by using the correlation function and two penalty terms for deviations from observed values (through penalty_observed=1) and initially forecasted figures (through _penalty_forecast_0=.5). These penalty terms can be amended by a practitioner pending the context.
Two tracker series are introduced given the starting point. The base tracker series (blue line) co-moves with the green series with a correlation coefficient of 0.742. The optimised series (red line) is optimised to maximise the correlation while penalising deviations from the base series. The optimised series has a correlation coefficient of 0.812. See the figure below for a comparison.