FN6806: Object Oriented Programming

news/2024/12/18 19:58:11/文章来源:https://www.cnblogs.com/MATH1131/p/18614676

FN6806: Object Oriented Programming II

Question 3-1

Implement Vasicek model for interest rate simulation𝑑𝑟(𝑡) = 𝜅 [𝜇 − 𝑟(𝑡)] 𝑑𝑡 + 𝜎𝑑𝑊(𝑡)𝑟(𝑡 + 1) = 𝑟(𝑡) + 𝜅 [𝜇 − 𝑟(𝑡)] Δ𝑡 + 𝜎√ Δ𝑡𝑧

  • Use Euler-Maruyama method to generate the paths. returned value is a tuple: 1) the endrates of all paths, 2) the sum of all rates of all paths (except the starting 𝑟0 ).You could use either vector or valarray for the result.The parameters are 𝑟0= 5%, 𝜎 (𝑠𝑑) = 10%, 𝜅 (kappa) = 0.82, 𝜇 (𝑟𝑚𝑒𝑎𝑛) = 5%, 𝑇 = 0.5, 𝑑𝑡 =1.0/365.0, 𝑝𝑎𝑡ℎ𝑠 = 20,000, 𝑠𝑡𝑒𝑝𝑠 = 𝑖𝑛𝑡(𝑇 ∗ 365).

uto vasicek(double sd, double kappa, double r_mean, double r0,double T, int paths, int steps, mt19937 &gen) {double dt = T / steps;vector<double> sum_rates(paths);vector<double> end_rates(paths);^^.return make_tuple(end_rates, sum_rates);}auto vasicek_valarray(double sd, double kappa, double r_mean,double r0, double T, int paths, int steps, mt19937 &gen) {double dt = T / steps;valarray<double> sum_rates(0.0, paths);valarray<double> end_rates(r0, paths);^^.return make_tuple(end_rates, sum_rates);}

  • Below is my test code and result as reference. You could adapt it to test your result.

seed_seq seed{90127};auto mtgen = mt19937{seed};auto [end_rates, sum_rates] =

vasicek(sd, kappa, r_mean, r0, T, 20'000, int(0.5 * 365),mtgen);auto end_rates_avg =accumulate(end_rates.begin(), end_rates.end(), 0.0) /end_rates.size();1auto sum_rates_avg =accumulate(sum_rates.begin(), sum_rates.end(), 0.0) /sum_rates.size();cout ^< end_rates_avg ^< ", " ^< sum_rates_avg ^< "\n";

^/ 0.0495695, 9.05915mtgen.seed(seed);auto [end_rates2, sum_rates2] =vasicek_valarray(sd, kappa, r_mean, r0, T, 20'000, int(0.5 * 365), mtgen);end_rates_avg =accumulate(end_rates2.begin(), end_rates2.end(), 0.0) /end_rates2.size();sum_rates_avg =accumulate(sum_rates2.begin(), sum_rates2.end(), 0.0) /sum_rates2.size();cout ^< end_rates_avg ^< ", " ^< sum_rates_avg ^< "\n";^/ 0.0495608, 9.06302

2Question 3-2 A simulator for event-driven backtesting.There are two approaches in backtesting trading strategy: vectorized and event-driven.The vectorized approach is the most common one and consists of simulating the strategy directly on historical data. The price series are loaded as vectors and we use vectorized operations for both the trading strategy and the performance代写FN6806: Object Oriented Programming  metrics.For example, we can have a buy signal whenever Close > Open and sell signal whenever Close< Open, and porformance metric is the 1-day lagged signal times the return of the next day(assuming buy at next day Open). It’s fast to implement such backtesting. However, if we wantto simulate for adding the number of orders when we have 2nd buy signal, we need to modifythe algorithm but it will not be easy. Vectorized method can not simulate the execution oforders realistically. At all, it is a simplified approach towards backtesting.The event-driven approach is more sophiscated as it simulates the strategy as if it was executedin real-time. The price series are loaded as a stream of ticks and the strategy is executed oneach tick, and various modules can be added at both sides: the exeuction side and the strategy side. For example, the exeuction could simulation the price slippage of the execution, thestrategy side could simulate for stop loss and dynamic order sizing depends on past performance. The event-driven approach is more flexible and more realistic, but it is more difficultto implement.In this exercise, you will read the source code of an event-driven simulator and try to understand how it works. You will need to document 5 places that exception couldoccur, what is theerror message, what could be the cause of the error and what could be the exception handling.Create a file exceptions.txt and write down your answers.This project will also be used in the Final quiz, so you should get familiar with it.

About the simulator:

  • Forked and modified from Aku https://github.com/flouthoc/aku/. I have made somechanges and you can get it by forking on Replit at https://replit.com/@YeKunlun/akufork?v=1
  • The author of this repo only made a start so it’s just a partial implementation. You wouldfind many rough edges: incomplete and incorrect.
  • In one-line explaination, it runs over a CSV file with each line as a tick. The tradingstrategy acts on the tick data and perform buy/sell operations.
  • All cpp files are in \src
  • All hpp files are in \include

Use Replit tools

  • When you press Run button, the program shasll run in the Console. However, you needto scroll back in history for the output.
  • You could use Code Search (Shortcut: Ctrl+Shift+F) to search for text in the project.
  • For manual mode, usually you don’t need to, you could open the Shell tool to type makefor compilation and then type ./main to run the program. make shall auto-detect anyrecently changed file and recompile the program. If you want to recompile every thing,make clean and then make.3Aku’s class organization
  • I created a simple chart to show the class organization of Aku’s simulator. You could useit as a reference.4

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/855001.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

R机器学习:朴素贝叶斯算法的理解与实操

最近又看了很多贝叶斯算法的一些文章,好多的文章对这个算法解释起来会放一大堆公式,对代数不好的人来说真的很头疼。本文尝试着用大白话写写这个算法,再做个例子,帮助大家理解和运用。Naive Bayes is a probabilistic machine learning algorithm based on the Bayes Theor…

[Linux]线程

线程 页表 每个进程都有一个虚拟地址空间,虚拟地址通过页表的映射找到对应的物理地址。那页表是如何完成虚拟地址到物理地址的映射的呢?其实一个程序在磁盘上的时候就以4KB为单位被划分成块,每一块称为页帧;而物理内存同样是以4KB为单位被划分,每一块称为页框。所以程序都…

Java框架 —— SpringMVC

MVC 分层MVC:Model View Controller(模型-视图-控制器)模型(Model):处理数据逻辑的部分;在web应用中,他通常包含与数据库交互的代码,负责数据的存储、检索和更新视图(View):将数据渲染为用户界面,视图只展示页面,不包含业务逻辑控制器(Controller):模型和视图…

2024-12-18 17 55 记录 Cambly trip`s summary and wher 1607b517085581159d14fe7750337be7

2024-12-18 17:55 记录 Cambly trip`s summary and where is the next ?https://tingwu.aliyun.com/doc/transcripts/g2y8qevxaayxnbeo?sl=1# 《2024-12-18 17:55 记录 Cambly trip`s summary and where is the next ?》1. 全文摘要 对话讲述了一个人通过使用美好的旅行来…

实验六 模板类、文件I/O和异常处理

1、实验任务一 Complex.hpp#pragma once#include <iostream> #include <stdexcept>// 声明 //////////////////////////////////////////////////// // 复数模板类声明 template<typename T> class Complex { public:Complex(T r = 0, T i = 0);Complex(cons…

免费设计Logo的新神器Slea.ai

使用Slea.ai,你可以在几分钟内设计出专业、高质量的Logo,支持多种场景应用,免费下载,实现自定义设计。品牌打造从未如此轻松!作为一名注重品牌形象的创作者或企业主,你是否苦于设计一款专业又独特的Logo?今天我要向大家推荐一个超级实用的网站——Slea.ai,它是一款免费的…

MOS管的寄生电容

我们经常看到,在电源电路中,功率MOS管的G极经常会串联一个小电阻,几欧姆到几十欧姆不等,那么这个电阻用什么作用呢? 这个电阻的作用有2个作用:限制G极电流,抑制振荡。 限制G极电流MOS管是由电压驱动的,是以G级电流很小,但是因为寄生电容的存在,在MOS管打开或关闭的时…

配置CentOS 7阿里yum源

备份yum源配置文件 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bakvi /etc/yum.repos.d/CentOS-Base.repo# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to …

源码信息收集

引子:上一篇主要介绍了与Web架构相关的信息收集,而在Web架构中有一至关重要的一环,那就是源码。Web应用中美观的ui、特色的功能全靠源码来实现,但同样的,几乎绝大多数与Web相关的漏洞都也都与其源码有关。而本篇则介绍几种常见的源码信息收集方式。附:完整笔记目录~ ps:…

标定和定位的关系

手眼标定手眼标定可以利用某真值位置和传感器观测位置对比得到外参。 关联本质上是外参不同引起的看同一外接参照物,认为自身运动轨迹的不同。位置如上观测同一建筑(三角形,上顶点是北方),真实轨迹(左图):是向北直行是在向正前方走世界坐标系->偏置传感器轨迹(中间图…