Академический Документы
Профессиональный Документы
Культура Документы
So Paulo
2010
So Paulo
2010
2
Pinheiro,Rebeca Nicolas
Estocstico On-Line- Negociao intraday/Rebeca Nicolas
Pinheiro So Paulo: Insper, 2010.
67 f.
Monografia: Faculdade de Economia e Administrao. Insper
Instituto de Ensino e Pesquisa.
Orientador: Prof. Dr. Marco Antonio Leonel Caetano
1.Sistema de Informao 2. VBA
Resumo
Pinheiro, Rebeca Nicolas. Estocstico On-Line Negociao Intraday. So Paulo, 2010. 67p.
Faculdade de Economia e Administrao. Insper Instituto de Ensino e Pesquisa.
Sumrio
1 Introduo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
2 Programa impresso em VBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1 Boto iniciar programa ---------------------------------------------------------------------------14
2.2 Boto iniciar aquisio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
2.3 boto parar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
2.4 Boto gfico ao . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..21
2.5 Boto grfico estocstico. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3 Exemplo do programa em funcionamento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
3.1 venda
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.2 compra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4Concluso. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
5Referncias. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1 Introduo
Sub CaixaDeTexto1_Clique()
UserForm1.Show
End Sub
Sub CapturaDados()
Dim x As Single
Dim r As Integer
Dim e As Integer
Dim min As Single
Dim max As Single
Dim fech As Single
Dim WSD As Worksheet
Dim WSW As Worksheet
Dim connectstring As String
Dim linharesfinal As Long
Dim i As Integer
Dim j As Integer
x=3
If h = 1 Then
8
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Worksheets("portfolio").Cells(proxlinha, 1) = Worksheets("workspace").Cells(6, 1).Value *
1
linharesfinal = WSW.Cells(65536, 1).End(xlUp).Row
For i = 1 To linharesfinal
For j = 1 To 20
WSW.Cells(i, j).EntireRow.Delete
Next j
Next i
min = 100
r=0
For r = proxlinha - 16 To proxlinha - 1
If Cells(r, 1) > max Then
max = Cells(r, 1)
ElseIf Cells(r, 1) < min Then
min = Cells(r, 1)
End If
Next r
fech = Cells(proxlinha - 1, 1)
Cells(proxlinha - 1, 4) = fech
Cells(proxlinha - 1, 3) = min
Cells(proxlinha - 1, 2) = max
If max = min Then
Cells(proxlinha - 1, 2) = "ao no oscilou nos 15 dados anteriores."
Else
est = 100 * ((fech - min) / (max - min))
Cells(proxlinha - 1, 5) = est
UserForm1.TextBox4 = est
If est >= 80 Then
Cells(proxlinha - 1, 6) = "vender"
UserForm1.TextBox5 = "vender"
ElseIf est <= 20 Then
Cells(proxlinha - 1, 6) = "comprar"
UserForm1.TextBox5 = "comprar"
Else
Cells(proxlinha - 1, 6) = "manter"
UserForm1.TextBox5 = "manter"
11
End If
End If
End If
End If
End Sub
Sub graficoacao()
Dim a As Single
If h = 3 Then
a = Worksheets("portfolio").Cells(65536, 1).End(xlUp).Row
Range("A3").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(Cells(3, 1), Cells(a, 1))
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.ChartArea.Copy
ActiveChart.Parent.Delete
Range("B2").Select
ActiveSheet.Paste
End If
End Sub
Sub graficoestoc()
Dim a As Single
12
If h = 4 Then
a = Worksheets("portfolio").Cells(65536, 1).End(xlUp).Row
Range("E18").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(Cells(18, 5), Cells(a, 5))
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.ChartArea.Copy
ActiveChart.Parent.Delete
Range("J2").Select
ActiveSheet.Paste
End If
End Sub
Private Sub CommandButton1_Click()
h=1
Call CapturaDados
End Sub
Private Sub CommandButton2_Click()
h=2
Call CapturaDados
End Sub
Private Sub CommandButton3_Click()
h=3
13
Call graficoacao
End Sub
Private Sub CommandButton4_Click()
h=4
Call graficoestoc
End Sub
2.1- Boto iniciar programa
14
15
Aps indicar no textbox1 o tempo de aquisio em que se deseja puxar os dados, e indicar no
tezxtbox2 a ao que deseja consultar . o usurio clica no boto iniciar aquisio, que remete
ao comando descrito a seguir:
Private Sub CommandButton1_Click()
h=1
Call CapturaDados
End Sub
E este remete ao programa captura dados pelo caal :
Sub CapturaDados()
Dim x As Single
Dim r As Integer
Dim e As Integer
Dim min As Single
Dim max As Single
Dim fech As Single
Dim WSD As Worksheet
Dim WSW As Worksheet
Dim connectstring As String
Dim linharesfinal As Long
Dim i As Integer
Dim j As Integer
x= 3
If h = 1 Then
( A FUNO IF ADICIONADA A ESSE COMANDO IMPE UMA CONDIO PARA
QUE O PROGRAMA RODE , ASSIM AO ACIONAR O BOTAO INICIAR AQUISIO
ELE IMPES H=1 E REMETE SUB CAPTURADADOS())
Set WSD = Worksheets("portfolio")
16
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Worksheets("portfolio").Cells(proxlinha, 1) = Worksheets("workspace").Cells(6, 1).Value *
1
(ESTE COMANDO FAZ COM QUE A PLANILHA 1 , PORTIFLIO, RECEBA NA
COLUNA A O VALOR DA AO APRESENTADO NA PLANILHA 2, WORKSPACE, )
linharesfinal = WSW.Cells(65536, 1).End(xlUp).Row
For i = 1 To linharesfinal
For j = 1 To 20
WSW.Cells(i, j).EntireRow.Delete
Next j
Next i
(DEPOIS DE ADICIONADO A PLANILHA PORTFLIO OS VALORES DA AO J
NO TEM MAIS UTILIDADE NA PLANILHA WORKSPACE E ASSIM ESTE
COMANDO DELETA TUDO QUE H NA PLANILHA WORKSPACE)
NextTime = Time + TimeSerial(0, 0, WaitSec)
'roda o relogio a cada prxima atualizao
18
End If
End If
End Sub
2.3 boto parar
Figura4.boto parar
Ao clicar no boto parar a private sub a seguir ser acionada
Private Sub CommandButton2_Click()
h=2
20
Call CapturaDados
End Sub
Este comando denomina o h =2 , sendo assim a condio IF para o programa inicial rodar
desativada , pois indica que hdeve ser igual a 1 para o programa comear a rodar.
2.4 boto grfico da ao
If h = 3 Then
a = Worksheets("portfolio").Cells(65536, 1).End(xlUp).Row
( este commando faz com que a macro encontre qual o nmero da ultima clula preenchida e
o chame de a)
Range("A3").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(Cells(3, 1), Cells(a, 1))
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.ChartArea.Copy
ActiveChart.Parent.Delete
Range("B2").Select
21
ActiveSheet.Paste
(A macro acima foi conseguida gravando macros, e os valores foram alterados para adequarse as necessidades)
End If
End Sub
2.5. boto grfico estocstico
If h = 4 Then
a = Worksheets("portfolio").Cells(65536, 1).End(xlUp).Row
Range("E18").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range(Cells(18, 5), Cells(a, 5))
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.ChartArea.Copy
ActiveChart.Parent.Delete
Range("J2").Select
ActiveSheet.Paste
End If
22
End Sub
3.Exemplo do prgrama em funcionamento
3.1 Venda
fechamento:28,6
mnimo:27,96
mximo:28,6
estocstico:100
23
3.2 compra
Fechamento:27,9
Mximo:27,96
Mnimo:27,9
Estocstico:0
24
5 Concluso
25
Referncias
Fruns de Excel .
Aulas do professor Marco Antnio Leonel Caetano
Parte do programa disponibilizado no netstudante
JELEN, Bill; SYRSTAD, Tracy. VBA e macros para microsoft office excel 2007. So Paulo:
Pearson Prentice Hall, c2009. 420 p. ISBN 9788576051954 (broch.)
26