joshuaulrich / joshuaulrich/quantmod

setSymbolLookup symbol rename should rename columns

Open
#137 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
906
Forks
233
PR merge metrics
No merged PRs in 30d

Description

One of the features of `setSymbolLookup` is to specify lookup details on a per-symbol basis, including:

> an alternate naming convention (useful for sites like Yahoo! where certain non-traded symbols are prepended with a caret, or more correctly a curcumflex accent. In that case one would specify `setSymbolLookup(DJI = list(name = "^DJI", src = "yahoo"))`)

But the object created/returned by `getSymbols` retains the column names from the original data source. For example, if you map the Shanghai Stock Exchange Composite Index from "000001.SS" to "SSE":

```r
setSymbolLookup(SSE = list(name = "000001.SS"))
getSymbols("SSE")
head(OHLC(SSE))
000001.SS.Open 000001.SS.High 000001.SS.Low 000001.SS.Close
2000-01-03 1366.58 1366.58 1366.58 1366.58
2000-01-04 1406.37 1406.37 1406.37 1406.37
2000-01-05 1409.68 1409.68 1409.68 1409.68
2000-01-06 1463.94 1463.94 1463.94 1463.94
2000-01-07 1516.60 1516.60 1516.60 1516.60
2000-01-10 1545.11 1545.11 1545.11 1545.11
```

Whereas it would be reasonable to expect the result to be:

```r
head(OHLC(SSE))
SSE.Open SSE.High SSE.Low SSE.Close
2000-01-03 1366.58 1366.58 1366.58 1366.58
2000-01-04 1406.37 1406.37 1406.37 1406.37
2000-01-05 1409.68 1409.68 1409.68 1409.68
2000-01-06 1463.94 1463.94 1463.94 1463.94
2000-01-07 1516.60 1516.60 1516.60 1516.60
2000-01-10 1545.11 1545.11 1545.11 1545.11
```

This is particularly useful when the symbol names are not valid R object names, since some R functions (e.g. `lm`) expect column names to be valid R object names.

**NB**: It might also be useful to include an attribute on the result that indicates the original symbol name for the given data source. I haven't looked at the code, so I'm not sure how easy/hard that might be.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing setSymbolLookup and getSymbols to find where source-derived column names are assigned, then inspect how OHLC(SSE) reads them. Done means a lookup such as SSE = list(name = "000001.SS") produces SSE.Open, SSE.High, SSE.Low, and SSE.Close columns without changing the data values.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.