bovespa_ingestion 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +11 -0
- data/Gemfile.lock +49 -0
- data/README.md +51 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/archives/SeriesHistoricas_Layout.pdf +0 -0
- data/bin/carregar_historico +22 -0
- data/bovespa_ingestion.gemspec +80 -0
- data/config/environment.rb +10 -0
- data/db/config.yml +22 -0
- data/db/migrate/20111221001450_create_historico.rb +15 -0
- data/db/migrate/20111222192119_create_ativos.rb +28 -0
- data/db/migrate/20111223004105_change_ativos.rb +10 -0
- data/db/migrate/20111223023840_add_quantidade_ativos_to_historico_ativos.rb +9 -0
- data/db/migrate/20111223131703_add_prazo_termo_to_ativo.rb +9 -0
- data/db/migrate/20111223213342_alter_reference_historico_ativo.rb +13 -0
- data/db/migrate/20111223214919_remove_data_importacao.rb +9 -0
- data/db/schema.rb +51 -0
- data/lib/historico_ativos/ativo.rb +6 -0
- data/lib/historico_ativos/carrega_historico.rb +32 -0
- data/lib/historico_ativos/header.rb +5 -0
- data/lib/historico_ativos/historico.rb +17 -0
- data/lib/historico_ativos/parser_ativo.rb +114 -0
- data/lib/historico_ativos/parser_header.rb +32 -0
- data/lib/historico_ativos/parser_trailer.rb +17 -0
- data/lib/historico_ativos/trailer.rb +5 -0
- data/lib/historico_ativos.rb +9 -0
- data/sample/DemoCotacoesHistoricas12022003.txt +553 -0
- data/sample/sample_cota_hist_2003.txt +4 -0
- data/spec/historico_ativos/ativo_spec.rb +12 -0
- data/spec/historico_ativos/carrega_historico_spec.rb +77 -0
- data/spec/historico_ativos/historico_spec.rb +40 -0
- data/spec/historico_ativos/parser_ativo_spec.rb +91 -0
- data/spec/historico_ativos/parser_header_spec.rb +31 -0
- data/spec/historico_ativos/parser_trailer_spec.rb +24 -0
- data/spec/spec_helper.rb +1 -0
- metadata +124 -0
@@ -0,0 +1,4 @@
|
|
1
|
+
00COTAHIST.2003BOVESPA 20040531
|
2
|
+
012003021202VALE3 010VALE R DOCE ON R$ 000000001050100000000105010000000010250000000001036800000000103210000000010321000000001043800142000000000000069500000000000720641400000000000000009999123100000010000000000000BRVALEACNOR0159
|
3
|
+
012003021262VALE5T 030VALE PNA 030R$ 000000001019300000000101940000000010193000000001019300000000101940000000000000000000000000000002000000000000001000000000000010193346000000000000009999123100000010000000000000BRVALEACNPA3160
|
4
|
+
99COTAHIST.2003BOVESPA 2004053100000000553
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HistoricoAtivos
|
4
|
+
describe CarregaHistorico do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@file = "sample/sample_cota_hist_2003.txt"
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:parser_header) { double(ParserHeader).as_null_object }
|
11
|
+
let(:parser_trailer) { double(ParserTrailer).as_null_object }
|
12
|
+
let(:parser_ativo) {
|
13
|
+
p_ativo = double(ParserAtivo).as_null_object
|
14
|
+
p_ativo.stub(:parse).and_return(Ativo.new)
|
15
|
+
p_ativo
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:loader) { CarregaHistorico.new parser_header, parser_trailer, parser_ativo }
|
19
|
+
let(:header) { double(Header).as_null_object }
|
20
|
+
let(:trailer) { double(Trailer).as_null_object }
|
21
|
+
|
22
|
+
it "deveria carregar o arquivo de exemplo" do
|
23
|
+
File.exists?(@file).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "deveria parsear header uma vez" do
|
27
|
+
parser_header.should_receive(:parse).once.and_return(Header.new)
|
28
|
+
|
29
|
+
loader.load @file
|
30
|
+
end
|
31
|
+
|
32
|
+
it "deveria parsear trailer uma vez" do
|
33
|
+
parser_trailer.should_receive(:parse).once.and_return(Trailer.new)
|
34
|
+
|
35
|
+
loader.load @file
|
36
|
+
end
|
37
|
+
|
38
|
+
it "deveria parsear ativo duas vezes" do
|
39
|
+
parser_ativo.should_receive(:parse).twice
|
40
|
+
|
41
|
+
loader.load @file
|
42
|
+
end
|
43
|
+
|
44
|
+
it "deveria retornar dois ativos ao carregar o arquivo" do
|
45
|
+
loader = CarregaHistorico.new parser_header, parser_trailer, ParserAtivo.new
|
46
|
+
|
47
|
+
historico = loader.load @file
|
48
|
+
|
49
|
+
historico.ativos.size.should == 2
|
50
|
+
historico.ativos[0].codigo.should == "VALE3"
|
51
|
+
historico.ativos[1].codigo.should == "VALE5T"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "deveria importar o header ao carregar o arquivo" do
|
55
|
+
header.stub(:nome_arquivo).and_return("COTAHIST.2003")
|
56
|
+
parser_header.stub(:parse).and_return(header)
|
57
|
+
|
58
|
+
historico = loader.load @file
|
59
|
+
historico.nome_arquivo.should == "COTAHIST.2003"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "deveria importar o trailer ao carregar o arquivo" do
|
63
|
+
trailer.stub(:quantidade_ativos).and_return(553)
|
64
|
+
parser_trailer.stub(:parse).and_return(trailer)
|
65
|
+
|
66
|
+
historico = loader.load @file
|
67
|
+
historico.quantidade_ativos.should == 553
|
68
|
+
end
|
69
|
+
|
70
|
+
it "deveria persistir o historico" do
|
71
|
+
historico = double(Historico).as_null_object
|
72
|
+
historico.should_receive(:save).once
|
73
|
+
|
74
|
+
loader.persist historico
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HistoricoAtivos
|
4
|
+
describe Historico do
|
5
|
+
|
6
|
+
let(:header) {
|
7
|
+
header = Header.new
|
8
|
+
header.nome_arquivo = "COTA.HIST2003"
|
9
|
+
header.codigo_origem = "BOVESPA"
|
10
|
+
header.data_geracao = Date.new(2004, 05, 31)
|
11
|
+
header
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:trailer) {
|
15
|
+
trailer = Trailer.new
|
16
|
+
trailer.quantidade_ativos = 553
|
17
|
+
trailer
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:historico) { Historico.new }
|
21
|
+
|
22
|
+
it "deveria carregar dados contidos no header" do
|
23
|
+
historico.import_header header
|
24
|
+
|
25
|
+
historico.nome_arquivo.should == "COTA.HIST2003"
|
26
|
+
historico.codigo_origem.should == "BOVESPA"
|
27
|
+
historico.data_geracao.to_s.should eql Date.new(2004, 05, 31).to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
it "deveria carregar dados contidos no trailer" do
|
31
|
+
historico.import_trailer trailer
|
32
|
+
|
33
|
+
historico.quantidade_ativos == 553
|
34
|
+
end
|
35
|
+
|
36
|
+
it "deveria ser activerecord" do
|
37
|
+
historico.should be_kind_of(ActiveRecord::Base)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HistoricoAtivos
|
4
|
+
describe ParserAtivo do
|
5
|
+
before(:each) do
|
6
|
+
sample_row = "012003021202VALE3 |010VALE R DOCE|ON | 1R$ |000000001050100000000105010000000010250000000001036800000000103210000000010321000000001043800142000000000000069500000000000720641400000000000000009999123100000010000000000000BRVALEACNOR0159"
|
7
|
+
parser = ParserAtivo.new
|
8
|
+
@ativo = parser.parse sample_row
|
9
|
+
end
|
10
|
+
|
11
|
+
it "deveria retornar nil se a linha nao comecar com 01" do
|
12
|
+
sample_row = "052003021202VALE3 |010VALE R DOCE|ON | 1R$ |000000001050100000000105010000000010250000000001036800000000103210000000010321000000001043800142000000000000069500000000000720641400000000000000009999123100000010000000000000BRVALEACNOR0159"
|
13
|
+
parser = ParserAtivo.new
|
14
|
+
ativo = parser.parse sample_row
|
15
|
+
|
16
|
+
ativo.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "deveria extrair ativo contendo data" do
|
20
|
+
@ativo.data.to_s.should eql Date.new(2003, 2, 12).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
it "deveria extrair ativo contendo codigo BDI" do
|
24
|
+
@ativo.codigo_bdi.should == 02
|
25
|
+
end
|
26
|
+
|
27
|
+
it "deveria extrair ativo contendo codigo" do
|
28
|
+
@ativo.codigo.should == "VALE3 |"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "deveria extrair ativo contendo tipo de mercado" do
|
32
|
+
@ativo.tipo_mercado.should == 10
|
33
|
+
end
|
34
|
+
|
35
|
+
it "deveria extrair ativo contendo nome" do
|
36
|
+
@ativo.nome.should == "VALE R DOCE|"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "deveria extrair ativo contendo especificacao" do
|
40
|
+
@ativo.especificacao.should == "ON |"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "deveria extrair ativo contendo prazo em dias do mercado a termo" do
|
44
|
+
@ativo.prazo_termo.should == 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "deveria extrair ativo contendo moeda de referencia" do
|
48
|
+
@ativo.moeda_referencia.should == "R$ |"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "deveria extrair ativo contendo preco de abertura" do
|
52
|
+
@ativo.preco_abertura.should == 105.01
|
53
|
+
end
|
54
|
+
|
55
|
+
it "deveria extrair ativo contendo preco maximo" do
|
56
|
+
@ativo.preco_maximo.should == 105.01
|
57
|
+
end
|
58
|
+
|
59
|
+
it "deveria extrair ativo contendo preco minimo" do
|
60
|
+
@ativo.preco_minimo.should == 102.50
|
61
|
+
end
|
62
|
+
|
63
|
+
it "deveria extrair ativo contendo preco medio" do
|
64
|
+
@ativo.preco_medio.should == 103.68
|
65
|
+
end
|
66
|
+
|
67
|
+
it "deveria extrair ativo contendo preco ultimo" do
|
68
|
+
@ativo.preco_ultimo.should == 103.21
|
69
|
+
end
|
70
|
+
|
71
|
+
it "deveria extrair ativo contendo preco da melhor oferta de compra" do
|
72
|
+
@ativo.preco_melhor_oferta_compra.should == 103.21
|
73
|
+
end
|
74
|
+
|
75
|
+
it "deveria extrair ativo contendo preco da melhor oferta de venda" do
|
76
|
+
@ativo.preco_melhor_oferta_venda.should == 104.38
|
77
|
+
end
|
78
|
+
|
79
|
+
it "deveria extrair ativo contendo total de negocios" do
|
80
|
+
@ativo.total_negocios.should == 142
|
81
|
+
end
|
82
|
+
|
83
|
+
it "deveria extrair ativo contendo quantidade de titulos negociados" do
|
84
|
+
@ativo.quantidade_titulos_negociados.should == 69500
|
85
|
+
end
|
86
|
+
|
87
|
+
it "deveria extrair ativo contendo volume de negocios" do
|
88
|
+
@ativo.volume_negocios.should == 720641400
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HistoricoAtivos
|
4
|
+
describe ParserHeader do
|
5
|
+
before(:each) do
|
6
|
+
sample_row = "00COTAHIST.2003BOVESPA 20040531 "
|
7
|
+
parser = ParserHeader.new
|
8
|
+
@header = parser.parse sample_row
|
9
|
+
end
|
10
|
+
|
11
|
+
it "deveria retornar nil se a linha nao comecar com 00" do
|
12
|
+
sample_row = "05COTAHIST.2003BOVESPA 20040531 "
|
13
|
+
parser = ParserHeader.new
|
14
|
+
header = parser.parse sample_row
|
15
|
+
|
16
|
+
header.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "deveria extrair header contendo o nome do arquivo lido" do
|
20
|
+
@header.nome_arquivo.should == "COTAHIST.2003"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "deveria extrair header contendo codigo origem" do
|
24
|
+
@header.codigo_origem.should == "BOVESPA"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "deveria extrair header contendo a data de geracao do arquivo" do
|
28
|
+
@header.data_geracao.to_s.should eql Date.new(2004, 05, 31).to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module HistoricoAtivos
|
4
|
+
describe ParserTrailer do
|
5
|
+
before(:each) do
|
6
|
+
sample_row = "99COTAHIST.2003BOVESPA 2004053199999999999 "
|
7
|
+
parser = ParserTrailer.new
|
8
|
+
@trailer = parser.parse sample_row
|
9
|
+
end
|
10
|
+
|
11
|
+
it "deveria retornar nil se a linha nao comecar com 99" do
|
12
|
+
sample_row = "50COTAHIST.2003BOVESPA 2004053100000000553 "
|
13
|
+
parser = ParserTrailer.new
|
14
|
+
trailer = parser.parse sample_row
|
15
|
+
|
16
|
+
trailer.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "deveria extrair header contendo quantidade de ativos no arquivo lido" do
|
20
|
+
@trailer.quantidade_ativos.should == 99999999999
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'historico_ativos'
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bovespa_ingestion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Felipe Seixas
|
9
|
+
- Rodrigo Fraga
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-12-26 00:00:00 -02:00
|
15
|
+
default_executable: carregar_historico
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rake
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activerecord
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "3"
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *id002
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: standalone_migrations
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id003
|
50
|
+
description:
|
51
|
+
email: seixasfelipe@gmail.com
|
52
|
+
executables:
|
53
|
+
- carregar_historico
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- README.md
|
58
|
+
files:
|
59
|
+
- Gemfile
|
60
|
+
- Gemfile.lock
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- VERSION
|
64
|
+
- archives/SeriesHistoricas_Layout.pdf
|
65
|
+
- bin/carregar_historico
|
66
|
+
- bovespa_ingestion.gemspec
|
67
|
+
- config/environment.rb
|
68
|
+
- db/config.yml
|
69
|
+
- db/migrate/20111221001450_create_historico.rb
|
70
|
+
- db/migrate/20111222192119_create_ativos.rb
|
71
|
+
- db/migrate/20111223004105_change_ativos.rb
|
72
|
+
- db/migrate/20111223023840_add_quantidade_ativos_to_historico_ativos.rb
|
73
|
+
- db/migrate/20111223131703_add_prazo_termo_to_ativo.rb
|
74
|
+
- db/migrate/20111223213342_alter_reference_historico_ativo.rb
|
75
|
+
- db/migrate/20111223214919_remove_data_importacao.rb
|
76
|
+
- db/schema.rb
|
77
|
+
- lib/historico_ativos.rb
|
78
|
+
- lib/historico_ativos/ativo.rb
|
79
|
+
- lib/historico_ativos/carrega_historico.rb
|
80
|
+
- lib/historico_ativos/header.rb
|
81
|
+
- lib/historico_ativos/historico.rb
|
82
|
+
- lib/historico_ativos/parser_ativo.rb
|
83
|
+
- lib/historico_ativos/parser_header.rb
|
84
|
+
- lib/historico_ativos/parser_trailer.rb
|
85
|
+
- lib/historico_ativos/trailer.rb
|
86
|
+
- sample/DemoCotacoesHistoricas12022003.txt
|
87
|
+
- sample/sample_cota_hist_2003.txt
|
88
|
+
- spec/historico_ativos/ativo_spec.rb
|
89
|
+
- spec/historico_ativos/carrega_historico_spec.rb
|
90
|
+
- spec/historico_ativos/historico_spec.rb
|
91
|
+
- spec/historico_ativos/parser_ativo_spec.rb
|
92
|
+
- spec/historico_ativos/parser_header_spec.rb
|
93
|
+
- spec/historico_ativos/parser_trailer_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://github.com/seixasfelipe/bovespa-ingestion
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.6.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: An importer of historical quotations from BM&F Bovespa
|
123
|
+
test_files: []
|
124
|
+
|