Par exemple, voici un truc hyper-simple que j'ai écrit en seulement 2
heures aujourd'hui.
J'avais envie d'importer directement dans R des fichiers au format
metastock, avec sélection de la fréquence: daily, weekly...
Mais j'avais la flemme de ré-écrire une dll. C'est alors que je me
suis souvenu que j'avais un vieux tableur excel qui faisait déjà cela.
Ce fut un jeu d'enfant d'écrire cette petite routine sous R, pour
ré-utiliser l'intégralité des fonctionnalités de ce tableur.
De la même manière, c'est hyper-simple de transformer R en programme
temps réel. Il suffit d'utiliser le package RDCOMEvents, pour capter
les évenements d'un composant COM (Excel, Active X...).
Après un événement de type changement d'un prix, on lance
une routine R de son choix.
he he he LA VIE EST BELLE.
# Import parameters
Path <- "f:/Allprices/France/Indices"
Ticker <- "FR0003500008"
Startdate <- "20051004" # yyyymmdd max 5000 days ago
Enddate <- "20061006"
Frequency <- "M" # D, W or M
# Lauching Excel COM server
library(RDCOMClient)
excel <- COMCreate("Excel.Application")
spreadsheet <- excel$Workbooks()$Open("F:/TRADING/Statistical
studies/Lab notebook/Backtest Template")
#excel[["Visible"]] = TRUE
# Putting Import parameters into Excel
ImportSheet <- spreadsheet$Worksheets("Import")
ImportSheet$Activate()
ExcelTargetCell <- ImportSheet$Range(ImportSheet$Cells(1,3),
ImportSheet$Cells(1, 3))
ExcelTargetCell[["Value"]] <- Path
ExcelTargetCell <- ImportSheet$Range(ImportSheet$Cells(2,3),
ImportSheet$Cells(2, 3))
ExcelTargetCell[["Value"]] <- Ticker
ExcelTargetCell <- ImportSheet$Range(ImportSheet$Cells(4,3),
ImportSheet$Cells(4, 3))
ExcelTargetCell[["Value"]] <- Startdate
ExcelTargetCell <- ImportSheet$Range(ImportSheet$Cells(5,3),
ImportSheet$Cells(5, 3))
ExcelTargetCell[["Value"]] <- Enddate
ExcelTargetCell <- ImportSheet$Range(ImportSheet$Cells(7,3),
ImportSheet$Cells(7, 3))
ExcelTargetCell[["Value"]] <- Frequency
# Running VBA Import routine
excel$Run("ImportMain")
# Getting results back into R
CotationSheet <- spreadsheet$Worksheets("Cotations")
CotationSheet$Activate()
data <- unlist(CotationSheet$UsedRange()[["Value"]])
date <- data[2

length(data)/6)]
open <- as.numeric(data[(2+length(data)/6)

2*length(data)/6)])
high <- as.numeric(data[(2+2*length(data)/6)

3*length(data)/6)])
low <- as.numeric(data[(2+3*length(data)/6)

4*length(data)/6)])
close <- as.numeric(data[(2+4*length(data)/6)

5*length(data)/6)])
volume <- as.numeric(data[(2+5*length(data)/6)

6*length(data)/6)])
# exit Excel
spreadsheet$Close(FALSE)
excel$quit()